<template>
  <!-- 底部部分 -->
  <footer class="footer" v-if="isShow">
    <span class="todo-count"
      ><strong>{{itemCount }}</strong
      >剩余</span
    >
    <ul class="filters">
      <li>
        <a href="#/" @click="filter('all')" :class="{ selected: type === 'all' }">全部</a>
      </li>
      <li>
        <a href="#/active" @click="filter('active')" :class="{ selected: type === 'active' }">进行中</a>
      </li>
      <li>
        <a href="#/completed" @click="filter('completed')" :class="{ selected: type === 'completed' }">已完成</a
        >
      </li>
    </ul>
    <button class="clear-completed" v-show="isClearShow" @click="clearDone">
      清除已完成
    </button>
  </footer>
</template>
<script>
import { mapGetters } from 'vuex'

export default {
  data () {
    return {
      type: 'all',
      isShow: !this.isFooterShow
    }
  },
  props: {
  },
  computed: {
    ...mapGetters('todo', ['itemCount', 'isFooterShow', 'isClearShow'])
  },
  methods: {
    filter (val) {
      if (val === 'all') {
        this.$store.dispatch('todo/getList')
      } else if (val === 'active') {
        this.$store.dispatch('todo/activeList')
      } else if (val === 'completed') {
        this.$store.dispatch('todo/completedList')
        this.isShow = true
      }
      this.type = val
    },
    clearDone () {
      this.$store.dispatch('todo/clearDone')
    }
  }
}
</script>
